package algorithm.beforestart;

public class searchMatrix {

    public static boolean searchMatrix(int[][] matrix, int target) {

        int m = matrix.length;
        int n = matrix[0].length;
        int row=m-1 ;
        int col=0;
        while ( row>=0 && col<=n-1){
            if (target>matrix[row][col]){
                col++;
            }else if (target<matrix[row][col]){
                row--;
            }else {
                return true;
            }

        }
        return false;


    }

    public static void main(String[] args) {
        int[][] matrix ={{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}};

        System.out.println(searchMatrix(matrix,100));;
    }
}
